<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-系统管理">
</@frame.head>
<script type="text/javascript" src="${contextPath}/resources/js/tool/ckeditor/ckeditor.js"></script>
<div class="page-container">
	<form action="${contextPath}/crud/crud_update" method="post" id="update_form" name="update_form" enctype="multipart/form-data" target="hidden_iframe">
	<input type="hidden"  name="id" id="id" value="${crud.id}"/>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				商户名称：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="${crud.name}" placeholder="" id="name" name="name" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				商户类别：</label>
			<div class="formControls col-xs-6 col-sm-6">
	           <span class="select-box radius">
	           <select class="select"  name="crudType" id="crudType">
	           	
				<#list typeMap?keys as testKey>
				<#if typeMap[testKey]=crud.crudType>
				<option value="${testKey}" selected="selected">${typeMap[testKey]}</option>
				<#else>
				<option value="${testKey}" >              	${typeMap[testKey]}
     			</option>
				</#if>
				
				
				</#list>
	           </select>
	           </span>
			</div>
		</div>
		<#list "0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"?split(".") as k>
 		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<#if k=0><label for="">所在省市:</label></#if>
				<#if k!=0><label for="">&nbsp;&nbsp;&nbsp;&nbsp;</label></#if>
				</label>
			<div class="formControls col-xs-6 col-sm-6">
				<select id="provinceID_${k}" name="crudProCitys[${k}].province.provId"   onchange="showCity(this,${k})">
                        <option value="" >选择省份 </option>
                   <#list crudBasProvList as prov>
				        <option value="${prov.provId}"> ${prov.provName}</option>     
				   </#list>
		   		</select>
		   		<span id="citySpan_${k}">
		   		</span>
			</div>
		</div>
      	</#list>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				推荐等级：</label>
			<div class="formControls col-xs-6 col-sm-6">
				 <select class="select"  name="level" id="level">
				 	<option value="0" <#if crud.level==0>selected="selected"</#if> >低等</option>
				 	<option value="1" <#if crud.level==1>selected="selected"</#if> >中等</option>
				 	<option value="2" <#if crud.level==2>selected="selected"</#if> >高等</option>
				 </select>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				关键字：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="${crud.crudKeyWord}" placeholder="" id="crudKeyWord" name="crudKeyWord" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				商户大图：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="file" id="crudImage" name="crudImage" onchange="getFullPath(this,'big');">
					<div id="big_preview">
						<img id="big_images" width="462" height="105" style="clear:both; display:block; padding-left: 17px;" src="${crud.crudPic}" />
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				商户小图：</label>
			<div class="formControls col-xs-6 col-sm-6">
			<input type="file" id="crudImageSmall" name="crudImageSmall" onchange="getFullPath(this,'small');"/>
				<div id="small_preview">
					<img id="small_images" width="462" height="105" style="clear:both; display:block; padding-left: 17px;" src="${crud.crudSmallPic}"/>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				商户详情：</label>
			<div class="formControls col-xs-6 col-sm-10">
				<textarea id="crudInfo" name="crudInfo" rows="" cols="">${crud.crudInfo}</textarea>
				<script type="text/javascript">
					CKEDITOR.replace('crudInfo',{filebrowserUploadUrl : '${contextPath}/ckeditor/uploader?Type=File&crudID=${crud.id}&uploadModel=crud',filebrowserImageUploadUrl : '${contextPath}/ckeditor/uploader?Type=Image&crudID=${crud.id}&uploadModel=crud',filebrowserFlashUploadUrl : '${contextPath}/ckeditor/uploader?Type=Flash&crudID=${crud.id}&uploadModel=crud'});
	            </script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="button" onclick="update();"  value="&nbsp;&nbsp;修改&nbsp;&nbsp;">
			</div>
		</div>
	</form>
	<iframe id="hidden_iframe" name="hidden_iframe" hidden="hidden"></iframe>
</div>
<@frame.end "default">
</@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
var path="${contextPath}";
var crudProCitys = ${crudProCitys};
$(function(){
	for(var i in crudProCitys) {
		var proId = crudProCitys[i].split(":")[0];
		var cityId = crudProCitys[i].split(":")[1];
		$("#provinceID_" + i).val(proId);
		if(cityId != "") {
			$.ajax({
				type: "post",
				cache : false,
				async: false,
				url: path + "/crud/crud_showCity",
				data: {
					"provinceID": proId,
					"cunt": i
				},
				dataType : "html",
				success : function(data) {
				    $("#citySpan_" + i).html(data);
				    $("#cityID_" + i).val(cityId);
				},
				error : function() {
					
				}
			});
		}
	}
});

function showCity(obj, cunt){

    $.ajax({
			url : path + "/crud/crud_showCity",
			cache : false,
			type : 'post',
			dataType : 'html',
			data :{"provinceID":obj.value, "cunt":cunt},
            error : function() {
            },
			success : function(data) {
			    $("#citySpan_"+cunt).html(data); 
			}
	});
}
//图片尺寸读取
function getFullPath(file, size) {
	if(!picIsRule(file.value, true)) { // 上传的文件不是图片
		return false;
	}
	if (typeof(FileReader) == "undefined") {
		layer.alert("抱歉!浏览器版本太低了!不支持预览图片,换个浏览器试试吧~");
		return false;
	}
	if (file.files && file.files[0]) {
		var reader = new FileReader();
		reader.onload = function(e) {
			$("#" + size + "_images").attr("src", e.target.result);
		}
		reader.readAsDataURL(file.files[0]);
	}
 /*  var divName = size+"_preview";   
  var imgName = size+"_images"
 
  var isImag = picIsRule(obj.value,true);
  if(isImag){}else{
  	return false;
  }				
  var o = {};
  //alert(window.navigator.userAgent);
  if(obj){
	   if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
		   var imgserver = document.getElementById(imgName);
           imgserver.style.display = 'none';			      
	       var newPreview = document.getElementById(divName);		
	       obj.select();	
	       o.filename = document.selection.createRange().text;
            newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = o.filename;
            newPreview.style.width = "149px";
            newPreview.style.height = "128px";	
	    } else if (window.navigator.userAgent.indexOf("Firefox") >= 1 && obj.files) {
	      // firefox
	      o.filename = window.URL.createObjectURL(obj.files.item(0));
	 	  document.getElementById(imgName).src=o.filename;	        
	    } else {
	      o.filename = obj.value;
		  document.getElementById(imgName).src=o.filename;
	    }
  		return o;
  } */
}
function checksum(obj){
	
	var sum = 0; 

	for (var i=0; i<obj.val().length; i++){ 
   		var c = obj.val().charCodeAt(i); 

   		if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)){ 
   			sum++; 
   		}
   		else{     
   			sum+=2; 
   		} 
	}
	return sum;			
}   
function update(){
	
	if($("#name").val()==''){
		alert("请输入商户名称!");
		return;
	}
	
	if($("#crudType").val()==''){
		alert("请选择商户类别!");
		return;
	}
	
	var flag = false;
	var count = 0;
	for(var i=0; i<20; i++){
		var sProvID = "#provinceID_"+i;
		var sCityID = "#cityID_"+i;
		
		if($(sProvID).val()=='-1' && $(sCityID).val()==undefined){
			count = count +1;
		}
		if($(sProvID).val()!='-1' && $(sCityID).val()=='-1'){
			flag = true;
			break;
		}
	}
	
	if(count==20){
		alert("请选择省市所在地!");
		return;
	}else if(flag){
		alert("请选择省市所在地!");
		return;
	}
	$("#update_form").submit();
  /*  $("#update_form").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "200"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
                        parent.window.location.reload();
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        }
    }); */
}

function callBackMethod(flag) {
	if (flag == "200") {
       layer.msg('操作成功!',{icon:1,time:1000},function(){
           parent.window.location.reload();
       });
	} else if (flag == "500") {
		layer.alert("系统繁忙！");
	} else {
		layer.alert(message);
	}
}
//验证上传图片是否是jpg|gif|jpeg|png 中的一种

function picIsRule(picUrl,isNull){
	// 允许的图片类型
	var imgType = new Array("jpg","gif","jpeg","png");
	// 图片类型
	var fileType = "" ;
	// 判断图片类型是否符合
	var isImg = false;
	// 判断图片路径不问空
	if(isNull){
		if(picUrl == "" || picUrl == null ){
			alert("图片不能为空！");
			isImg = false;
			return false;
		}
		// 获取图片的最后类型 根据最后的一个.判断
		fileType = picUrl.substring(picUrl.lastIndexOf(".")+1, picUrl.length);
		for(var i=0 ;i<imgType.length;i++){			
			if(fileType.toLowerCase() == imgType[i]){
				isImg = true;
				break;
			}
		}
	}else{
		if(picUrl == "" || picUrl == null ){			
			isImg = true;
			return true;
		}else{
			// 获取图片的最后类型 根据最后的一个.判断
			fileType = picUrl.substring(picUrl.lastIndexOf(".")+1, picUrl.length);
			for(var i=0 ;i<imgType.length;i++){			
				if(fileType.toLowerCase() == imgType[i]){
					isImg = true;
					break;
				}
			}
		}
	}
	if(isImg){
		return true;
	}else{
		alert("上传图片类型错误，只能上传jpg|gif|jpeg|png类型图片！");
		return false;
	}
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
</body>
</html>